﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Common.Infrastructure
{
    public static class LibCheckNullUtils
    {
        /// <summary>
        /// 检查对象是否为空,如果为空，则抛出异常.
        /// </summary>
        /// <param name="obj">对象.</param>
        /// <param name="paramName">参数名.</param>
        public static void CheckNull(object obj, string paramName)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(paramName);
            }

            if (obj.GetType() == typeof(string))
            {
                var st = obj.ToString();
                if (string.IsNullOrEmpty(st))
                {
                    throw new ArgumentNullException(paramName);
                }
            }
            else if (obj.GetType() == typeof(int))
            {
                var st = LibSysUtils.ToInt(obj);
                if (st == 0)
                {
                    throw new ArgumentNullException(paramName);
                }
            }
            else if (obj.GetType() == typeof(decimal))
            {
                var st = LibSysUtils.ToDecimal(obj);
                if (st == 0)
                {
                    throw new ArgumentNullException(paramName);
                }
            }
        }
    }
}
